package com.blb.day20231226redis.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blb.day20231226redis.pojo.ResponseResult;
import com.blb.day20231226redis.pojo.Score;
import com.blb.day20231226redis.service.ScoreService;
import com.blb.day20231226redis.service.StudentService;
import com.blb.day20231226redis.service.impl.ScoreServiceImpl;
import org.redisson.api.RBloomFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ScoreController {

    @Autowired
    private ScoreService scoreService;

    @Autowired
    private RBloomFilter<String> bloomFilter;

    /**
     * 初始化布隆过滤器
     * @return
     */
    @GetMapping("init-bloomfilter")
    public ResponseResult<String> initBloomFilter(){
        //查询所有的id
        List<Score> list = scoreService.list();
        //添加key到布隆过滤器
        list.forEach(score -> {
            bloomFilter.add(ScoreServiceImpl.PREFIX + score.getId());
        });
        return ResponseResult.ok("ok");
    }

    @GetMapping("score/{id}")
    public ResponseResult<Score> findScoreById( @PathVariable Long id){
        Score score = scoreService.getScoreById(id);
        return ResponseResult.ok(score);
    }


}
